//Copyright (C) 2009 Ron Coleman. Contact: ronncoleman@gmail.com
//
//This library is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 3 of the License, or (at your option) any later version.
//
//This library is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this library; if not, write to the Free Software
//Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

package org.workplicity.marist.grounds.ui.table;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import org.workplicity.entry.Comment;
import org.workplicity.marist.grounds.util.GroundsDate;
import org.workplicity.marist.grounds.util.GroundsHelper;

/**
 *
 * @author Ron Coleman
 */
public class CommentsTableModel extends AbstractTableModel {
    private String[] columnNames = {"Date",
                                    "User",
                                    "Comment"};

    private List<Comment> comments = new ArrayList<Comment>( );

    public CommentsTableModel() {

    }

    public List<Comment> getComments() {
        return comments;
    }

    public void setComments(List<Comment> comments) {
        this.comments = comments;
    }

    public int getRowCount() {
        return comments.size();
    }

    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public String getColumnName(int col) {
        return columnNames[col];
    }
    
    public Object getValueAt(int row, int col) {
        Comment comment = comments.get(row);

        if(col == 0)
            return new GroundsDate(comment.getDate());

        else if(col == 1)
            return GroundsHelper.getLogname(comment.getUserId());

        else
            return comment.getText();
    }

}
